{{- define "tarball" }} xxx  {{end -}}
- hosts: {{ .stepRun.HostGroup }}
  gather_facts: false
  vars:
    - tarball: "task-{{ .taskRun.TaskVerId }}-step-{{ .stepRun.DeliveryStepId }}.tar"
  # vars_files:
    # - "{{.varFile}}"
  tasks:
    - name: Package files
      shell: |
        set -xeuo pipefail
        cd {{ .stepRun.PlaybookDir}}
        [[ ! -f {{`{{`}} tarball {{`}}`}} ]] || rm {{`{{`}} tarball {{`}}`}}
        tar -hcvf {{`{{`}} tarball {{`}}`}} {{ .stepRun.DirName }}
      connection: local
      run_once: true

    - name: Check if working_dir exists
      stat:
        path: "{{ .stepRun.RemoteShellDir }}/"
      register: dir_stat

    - name: Clean working_dir before extracting
      file:
        path: "{{ .stepRun.RemoteShellDir }}/"
        state: absent
      when: dir_stat.stat.exists

    - name: Create working_dir
      file:
        path: "{{ .stepRun.RemoteShellDir }}/"
        mode: "0755"
        state: directory

    - name: Upload files
      unarchive:
        src: "{{ .stepRun.PlaybookDir}}/{{`{{`}} tarball {{`}}`}}"
        dest: "{{ .stepRun.RemoteShellDir }}/../"
        force: true
        mode: "0755"

    - name: run {{ .snapshot.Title }}
      shell: "cd {{ .stepRun.RemoteShellDir }};sh {{ .stepRun.RemoteShellFile }}"
{{- if .stepRun.SuUser}}
      become: true
{{- end }}